package com.scoy.honeymei.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.recyclerview.widget.RecyclerView;

import com.scoy.honeymei.R;
import com.scoy.honeymei.bean.AddressBean;
import com.scoy.honeymei.custem.LeftSwipeLayout;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @ClassName: NormalAdapter$
 * @Description:
 * @Author: GaoZhan
 * @CreateDate: 2019/8/26/0026$ 下午 17:03$
 * @UpdateUser: 更新者
 * @UpdateDate: 2019/8/26/0026$ 下午 17:03$
 * @UpdateRemark: 更新内容
 */
public class AddressAdapter extends RecyclerView.Adapter {
    private Context context;
    private ArrayList<AddressBean> datalist;
    private TextView notv;

    public AddressAdapter(Context context, ArrayList<AddressBean> datalist, TextView notv) {
        this.context = context;
        this.datalist = datalist;
        this.notv = notv;
    }

    public interface OnOneClick {
        void oneClick(int pos);
    }

    OnOneClick onOneClick;

    public void setOnOneClick(OnOneClick onOneClick) {
        this.onOneClick = onOneClick;
    }

    public interface OnTwoClick {
        void twoClick(int pos);
    }

    OnTwoClick onTwoClick;

    public void setOnTwoClick(OnTwoClick onTwoClick) {
        this.onTwoClick = onTwoClick;
    }

    public interface OnThreeClick {
        void threeClick(int pos);
    }

    OnThreeClick onThreeClick;

    public void setOnThreeClick(OnThreeClick onThreeClick) {
        this.onThreeClick = onThreeClick;
    }



    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_address, parent, false);
        return new AddressHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        AddressHolder addressHolder = (AddressHolder) holder;
        AddressBean addressBean = datalist.get(position);
        addressHolder.iadNameTv.setText(addressBean.getUsername());
        addressHolder.iadContentTv.setText(addressBean.getArea() + addressBean.getAddressdetail());
        addressHolder.iadPhoneTv.setText(addressBean.getPhone());

        addressHolder.delete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onOneClick != null) {
                    onOneClick.oneClick(position);
                }
            }
        });
        addressHolder.iadEditTv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onTwoClick != null) {
                    onTwoClick.twoClick(position);
                }
            }
        });

        addressHolder.checkaddresCl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(onThreeClick!=null){
                    onThreeClick.threeClick(position);

                }
            }
        });
    }

    @Override
    public int getItemCount() {
        int iCount = datalist == null ? 0 : datalist.size();
        if (iCount == 0) {
            notv.setVisibility(View.VISIBLE);
        } else {
            notv.setVisibility(View.GONE);
        }
        return iCount;

    }

    class AddressHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.iad_name_tv)
        TextView iadNameTv;
        @BindView(R.id.iad_phone_tv)
        TextView iadPhoneTv;
        @BindView(R.id.iad_content_tv)
        TextView iadContentTv;
        @BindView(R.id.iad_line)
        View iadLine;
        @BindView(R.id.iad_edit_tv)
        TextView iadEditTv;
        @BindView(R.id.delete)
        TextView delete;
        @BindView(R.id.item_address)
        LeftSwipeLayout itemAddress;
        @BindView(R.id.checkaddres_cl)
        ConstraintLayout checkaddresCl;

        AddressHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }

}
